﻿namespace ShiQuan.IotDevice.Mapping
{
    using System;
    using System.Data.Common;
    using System.Data.Entity;
    using System.Data.Entity.ModelConfiguration.Conventions;
    using System.Linq;

    public class IotDeviceDbContext : DbContext
    {
        //您的上下文已配置为从您的应用程序的配置文件(App.config 或 Web.config)
        //使用“IotDeviceDbContext”连接字符串。默认情况下，此连接字符串针对您的 LocalDb 实例上的
        //“ShiQuan.IotDevice.Mapping.IotDeviceDbContext”数据库。
        // 
        //如果您想要针对其他数据库和/或数据库提供程序，请在应用程序配置文件中修改“IotDeviceDbContext”
        //连接字符串。
        public IotDeviceDbContext()
            : base("name=IotDeviceDb")
        {
        }

        public IotDeviceDbContext(string connectionString)
            : base(connectionString)
        {
        }

        public IotDeviceDbContext(DbConnection dbConnection, bool contextOwnsConnection = true)
            : base(dbConnection, contextOwnsConnection)
        {
        }
        //为您要在模型中包含的每种实体类型都添加 DbSet。有关配置和使用 Code First  模型
        //的详细信息，请参阅 http://go.microsoft.com/fwlink/?LinkId=390109。

        // public virtual DbSet<MyEntity> MyEntities { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Configurations.Add(new SupplierInfoMap());
            modelBuilder.Configurations.Add(new IotDeviceInfoMap());
            modelBuilder.Configurations.Add(new IotDeviceSensorMap());
            modelBuilder.Configurations.Add(new CustomerInfoMap());
            modelBuilder.Configurations.Add(new IotDeviceInstallMap());
            modelBuilder.Configurations.Add(new IotDeviceLastMap());
            modelBuilder.Configurations.Add(new IotDeviceDataMap());
            
            modelBuilder.Configurations.Add(new DeviceInfoMap());
            modelBuilder.Configurations.Add(new DeviceInstallMap());
            modelBuilder.Configurations.Add(new DeviceDataMap());
            /*农残检测管理*/
            modelBuilder.Configurations.Add(new SampleInfoMap());
            modelBuilder.Configurations.Add(new DetectionItemMap());
            modelBuilder.Configurations.Add(new DetectionResultMap());

            base.OnModelCreating(modelBuilder);
        }
    }
}